/*
 * @Author: your name
 * @Date: 2020-07-08 13:47:57
 * @LastEditTime: 2020-08-05 09:51:11
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \dashboard\src\utils\AMap.js
 */
export default function MapLoader() {
  return new Promise((resolve, reject) => {
    if (window.AMap) {
      resolve(window.AMap)
    } else {
      var script = document.createElement('script')
      script.type = 'text/javascript'
      script.async = true
      script.src =
          'https://webapi.amap.com/maps?v=1.4.15&key=52a208e99a6c24ab60208167d15cb5db&plugin=AMap.MouseTool,AMap.PolyEditor,Map3D,AMap.DistrictSearch'
      script.onerror = reject
      document.head.appendChild(script)
      script.onload = function() {
        setTimeout(() => {
          resolve(window.AMap)
        }, 1000)
      }
    }
  })
}

